import { defineConfig } from 'vite'
import path from 'node:path'
import electron from 'vite-plugin-electron/simple'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  base:'./',
  plugins: [
    vue(),
    electron({
      main: {
        // Shortcut of `build.lib.entry`.
        entry: 'electron/main.ts',
      },
      preload: {
        // Shortcut of `build.rollupOptions.input`.
        // Preload scripts may contain Web assets, so use the `build.rollupOptions.input` instead `build.lib.entry`.
        input: path.resolve('electron/preload.ts'),
      },
      // Ployfill the Electron and Node.js API for Renderer process.
      // If you want use Node.js in Renderer process, the `nodeIntegration` needs to be enabled in the Main process.
      // See 👉 https://github.com/electron-vite/vite-plugin-electron-renderer
      renderer: {},
    }),
  ],
  server: {
    port: 3000,
    proxy: {
      '/pl': 'http://localhost:3000',
    },
  },
  build: {
    outDir: 'web-dist', // 确保构建输出目录正确
    assetsDir: 'assets', // 指定静态资源的输出目录
    rollupOptions: {
      external: ['nodemailer', 'child_process','/plugins/**'],
      output: {
        manualChunks: {
          vue: ['vue', 'vue-router'],
          ui: ['element-plus'],
          utils: ['xlsx', 'playwright'],
          electron: ['electron', 'electron-log']
        }
      }
    },
  },
  // optimizeDeps配置，预构建常用依赖，减少首次启动时编译时间
  optimizeDeps: {
    include: [
      'vue',
      'electron',
      'element-plus',
    ],
    exclude: ['nodemailer']
  },
})

